<?php

require_once 'common/conn.php';
require_once 'common/common.php';

$db = new DBC();
$sql = "SELECT * FROM t_search_info ORDER BY id LIMIT 9";
$data = $db->fetchData($sql);
$url = "http://www.lz06.com/admin/";
if (checkArrayNotEmpty($data)) {
    for ($i = 0; $i < count($data); $i++) {
        if ($data[$i]['imageURL'] == null || $data[$i]['imageURL'] == "null" || $data[$i]['imageURL'] == "") {
            $data[$i]['imageURL'] = "";
        } else {
            $data[$i]['imageURL'] = $url . $data[$i]['imageURL'];
        }
        if (hasProductByInfoID($data[$i]['id'])) {
            $data[$i]['hasProduct'] = 1;
        } else {
            $data[$i]['hasProduct'] = 0;
        }
    }
}

echo json_encode($data);

function hasProductByInfoID($id) {
    $db = new DBC();
    $sql = "SELECT id FROM t_search_detail WHERE infoID = " . $id;
    $data = $db->fetchData($sql);
    if (checkArrayNotEmpty($data)) {
        return true;
    }
    return false;
}

?>